#include <assert.h>
#include <gfx/multimesh.h>

ceMultiMesh::ceMultiMesh()
  : _indices(0)
  , _vertexDeclaration(0)
  , _primCount(0)
  , _indexDataType(DT_UnsignedShort)
{
  CE_OBJECT_CONSTR
	_vertices.clear ();
}

unsigned ceMultiMesh::GetNumberOfVertexBuffers () const
{
	return _vertices.size ();
}

void ceMultiMesh::AddVertices (iVertexBuffer* vertices)
{
	_vertices.push_back (vertices);
}

void ceMultiMesh::SetVertices(unsigned idx, iVertexBuffer *vertices)
{
	assert (idx < _vertices.size ());
	_vertices[idx] = vertices;
}

iVertexBuffer* ceMultiMesh::GetVertices(unsigned idx)
{
	assert (idx < _vertices.size ());
  return _vertices[idx];
}

const iVertexBuffer* ceMultiMesh::GetVertices(unsigned idx) const
{
	assert (idx < _vertices.size ());
  return _vertices[idx];
}

void ceMultiMesh::SetIndices(iIndexBuffer *indices)
{
  _indices = indices;
}

iIndexBuffer* ceMultiMesh::GetIndices()
{
  return _indices;
}

const iIndexBuffer* ceMultiMesh::GetIndices() const
{
  return _indices;
}

void ceMultiMesh::SetVertexDeclaration(iVertexDeclaration *vertexDeclaration)
{
  _vertexDeclaration = vertexDeclaration;
}

iVertexDeclaration* ceMultiMesh::GetVertexDeclration()
{
  return _vertexDeclaration;
}

void ceMultiMesh::SetBoundingBox(const ceBoundingBox &bbox)
{
  _bbox = bbox;
}

ceBoundingBox& ceMultiMesh::GetBoundingBox()
{
  return _bbox;
}

const ceBoundingBox& ceMultiMesh::GetBoundingBox() const
{
  return _bbox;
}

void ceMultiMesh::SetNumberOfTrigons(unsigned numberOfTrigons)
{
  _primCount = numberOfTrigons * 3;
}

unsigned ceMultiMesh::GetNumberOfTrigons() const
{
  return _primCount / 3;
}

void ceMultiMesh::SetNumberOfLines(unsigned numberOfLines)
{
  _primCount = numberOfLines * 2;
}

unsigned ceMultiMesh::GetNumberOfLines() const
{
  return _primCount / 2;
}

unsigned ceMultiMesh::GetNumberOfPrims() const
{
  return _primCount;
}

void ceMultiMesh::Set32BitIndices(bool bit32)
{
  _indexDataType = bit32 ? DT_UnsignedInt : DT_UnsignedShort;
}

bool ceMultiMesh::Is32BitIndices() const
{
  return _indexDataType == DT_UnsignedInt;
}

ceDataType ceMultiMesh::GetIndexDataType() const
{
  return _indexDataType;
}


